package vaannila;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.opensymphony.xwork2.ActionSupport;


public class WriteDB extends ActionSupport {

	private static final long serialVersionUID = 1L;

	//private String userName;
	//private String userID;
                  
	private String id;
	private String password;

	public WriteDB() { 
	}

	public String execute() {
		
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		

		try {
			String DB_SERVER = "localhost:3306";
			String DB_USERNAME = "root";
			String DB_PASSWORD = "tkfkdgo";
			String DB_DATABASE = "db_test";
			String DB_TABLE = "member";

			String jdbcUrl = "jdbc:mysql://" + DB_SERVER + "/" + DB_DATABASE;

			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager
					.getConnection(jdbcUrl, DB_USERNAME, DB_PASSWORD);

			String sql = "insert into member(userName, userID) values(?,?)";
			
			 
			//sql += "(?, ?)";
			ps = con.prepareStatement(sql);
			ps.setString(1, id);
			ps.setString(2, password);
			int r = ps.executeUpdate();
//
//			while (rs.next()) {
//				// userName = rs.getString(1);
//
//				return "input";
//			}
//		
			
		} catch (Exception e) {
			
			e.printStackTrace();
			return "fail";
		}

		finally {

			if (ps != null)

				try {
					ps.close();
				} catch (Exception e) {

				}

			if (con != null)
				try {

					con.close();
				}

				catch (Exception e) {

				}

		}
		return "input";
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
}
